﻿using System;
using System.Web.Mvc;
using Common;
using Controllers.Extend;
using Model.Database;
using Model.Sys.Config;

namespace Controllers.Controllers
{
    public class LogoutController : UserBaseController
    {
        protected override void OnAuthorization(AuthorizationContext filterContext)
        {
            base.cookieName = CookieConfig.UserInfoLoginCookieName;
            base.OnAuthorization(filterContext);
            if (loginUser == null)//身份失效，直接跳转登录页
            {
                filterContext.Result = new RedirectResult("/Login/Index");
            }
        }

        /// <summary>
        /// 登出操作
        /// </summary>
        /// <returns></returns>
        public ActionResult Index()
        {
            CurrentBllSession.CacheBll.Remove(CookieHelper.GetCookieValue(CookieConfig.UserInfoLoginCookieName));
            //登入登出记录
            Loginout loginout = new Loginout();
            loginout.LoginoutId = StringHelper.GetGuidString();
            loginout.UserInfoId = loginUser.UserInfoId;
            loginout.ActionType = "登出";
            loginout.Ip = loginUser.LastLoginIp;
            loginout.Description = "登出成功";
            loginout.AddTime = DateTime.Now;
            CurrentBllSession.LoginoutBll.Add(loginout);

            return Redirect("/Login/Index");
        }


    }
}
